package com.psjj.privilege.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * 数据源工具类
 */
public class DataSourceUtils {
    //创建Properties
    private static Properties properties = new Properties();
    //数据源
    private static DataSource dataSource;
    //加载数据源
    static{
        try {
            //读取配置文件
            properties.load(DataSourceUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
            //获取数据源
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //数据源获取方法
    public static DataSource getDataSource(){
        return dataSource;
    }
}
